
base = Rust
build = build

esHello= ../testfiles/testHelloWorld.rs
esT1E= ../testfiles/test1Errori.rs
esT2C= ../testfiles/test2Corretto.rs
esT2E= ../testfiles/test2Errori.rs
runnable = ./Test$(base)

BNFC     = bnfc
PDFLATEX = pdflatex
HAPPY    = happy -gca
ALEX     = alex -g
GHC      = ghc -O -outputdir $(build)


bnfcGenerHS   = Abs$(base).hs Print$(base).hs Test$(base).hs ErrM.hs
bnfcGenerated = $(bnfcGenerHS) Doc$(base).tex Par$(base).y Lex$(base).x
generatedHS   = Par$(base).hs Lex$(base).hs $(bnfcGenerHS)

.PHONY : all
all: $(generatedHS) Test$(base)
   

.PHONY : demo
demo: Test$(base)
	   $(runnable) $(esT1E)
	   
.PHONY : demo1
demo1: Test$(base)
	   $(runnable) $(esT2E)
	   
.PHONY : demo2
demo2: Test$(base)
	   $(runnable) $(esT2C)

.PHONY : hello
hello: Test$(base)
	   $(runnable) $(esHello)

.PHONY : clean
clean:
	rm -fv *.log *.aux *.bak *.happylog *.alexlog
	rm -fv Test$(base)
	rm -fv Par$(base).hs
	rm -fv Lex$(base).hs
	rm -fr $(build)
   
.PRECIOUS : Par%.y Lex%.x Doc%.tex

%.hs: %.y
	$(HAPPY) $< -i$*.happylog

%.hs: %.x
	$(ALEX) $< -i$*.alexlog


Test% : $(generatedHS) *%.hs 
	$(GHC) --make $@.hs  -o $@
	
